import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: '层序',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(
            seedColor: const Color.fromARGB(255, 255, 255, 255)),
        useMaterial3: true,
      ),
      home: const MyHomePage(title: '点名'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int _counter = 0;
  final TextEditingController _controller =
      TextEditingController(); // 创建一个文本控制器
  double _scale = 1.0; // 缩放比例
  bool _isDarkBackground = false; // 是否切换到黑色背景

  void _incrementCounter() {
    setState(() {
      _counter = int.tryParse(_controller.text) ?? 0; // 尝试将输入框的内容解析为整数
      _scale = 1.5; // 设置缩放比例为 1.5，使数字变大
    });
  }

  void _toggleBackground() {
    setState(() {
      _isDarkBackground = !_isDarkBackground; // 切换背景颜色状态
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            const Text(
              '按按钮的次数:',
            ),
            Transform.scale(
              // 使用 Transform.scale 实现缩放
              scale: _scale,
              child: Text(
                '$_counter',
                style: Theme.of(context).textTheme.headlineMedium,
              ),
            ),
            const SizedBox(height: 20), // 添加一些间距
            SizedBox(
              width: 200, // 设置输入框宽度
              child: TextField(
                controller: _controller, // 绑定控制器
                keyboardType: TextInputType.number, // 限制输入为数字
                decoration: const InputDecoration(
                  border: OutlineInputBorder(),
                  hintText: '请输入一个数字',
                ),
              ),
            ),
            const SizedBox(height: 20), // 添加一些间距
            ElevatedButton(
              // 添加一个按钮用于切换背景颜色
              onPressed: _toggleBackground,
              child: Text(_isDarkBackground ? '切换到白色背景' : '切换到黑色背景'),
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: '更新',
        child: const Icon(Icons.add),
      ),
      backgroundColor:
          _isDarkBackground ? Colors.black : Colors.white, // 根据状态设置背景颜色
    );
  }
}